package org.lbspoc.springboot1.boot.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.validation.constraints.NotNull;

import org.apache.log4j.Logger;
import org.lbspoc.springboot1.boot.validation.DoubleMinMax;

public class LbsInfo {
	private static Logger logger = Logger.getLogger(LbsInfo.class);
	private static String tsFormat = "yyyy-MM-dd HH:mm:ss";
	@NotNull
	private long user_id;
	@NotNull
	@DoubleMinMax(min=-90,max=90)
	private double latitude;
	@NotNull
	@DoubleMinMax(min=-180,max=180)
	private double longitude;
	@NotNull
	private String last_updated_ts;

	public LbsInfo() {
		// TODO Auto-generated constructor stub
	}

	
	public long getUser_id() {
		return user_id;
	}

	public void setUser_id(long user_id) {
		this.user_id = user_id;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public String getLast_updated_ts() {
		return last_updated_ts;
	}
	
	public Date lastUpdateTs() {
		if(this.last_updated_ts == null) return null;
		SimpleDateFormat sdf = new SimpleDateFormat(tsFormat);
		try {
			return sdf.parse(last_updated_ts);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			logger.error(e.getMessage(), e);
			return null;
		}
	}

	public void setLast_updated_ts(String last_updated_ts) {
		SimpleDateFormat sdf = new SimpleDateFormat(tsFormat);
		try {
			sdf.parse(last_updated_ts);
			this.last_updated_ts = last_updated_ts;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			logger.error(e.getMessage(), e);
		}
		
	}
	
	public void updateLastTs(Date d) {
		SimpleDateFormat sdf = new SimpleDateFormat(tsFormat);
		this.last_updated_ts = sdf.format(d);
	}
	
	public String toString() {
		return "[user_id:" + user_id + ",latitude:" + latitude 
				+ ",longitude:" + longitude + ",last_updated_ts:" + last_updated_ts;
	}

}
